<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
	</head>
	<body>
		<span id="container">1</span>
		<button id="button">点击加 1</button>

		<script>
			var obj = {
				value: 1
			}

			// 储存 obj.value 的值
			var value = 1

			Object.defineProperty(obj, 'value', {
				get: function () {
					console.log('get==>', value)
					return value
				},
				set: function (newValue) {
					obj.value = newValue
					// value = newValue
					// document.getElementById('container').innerHTML = newValue
					// console.log('set==>',value)
				}
			})

			document.getElementById('button').addEventListener('click', function () {
				obj.value += 1
			})
		</script>
	</body>
</html>
